package com.haizhi.crm.sys.dao;

import com.haizhi.crm.sys.bean.User;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.FetchType;
import javax.transaction.Transactional;
import java.util.List;

@Transactional
@Repository
public interface UserDao extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {

    @Query("select u from User u join fetch u.roles r where u.id = :id")
    User optimizedFindOne(@Param("id") String id);

    @Query("select u from User u where u.username = :username")
    User findByName(@Param("username") String username);

}
